package chapter12.section6;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
public class WeatherDemo{
    public static void main(String[] args) {
        try{
            URL url = new URL("http://t.weather.itboy.net/api/weather/city/101180101");
            InputStreamReader isReader =  new InputStreamReader(url.openStream(),"UTF-8");//“UTF- 8”万国码，可以显示中文，这是为了防止乱码
            BufferedReader br = new BufferedReader(isReader);//采用缓冲式读入
            String str;
            while((str = br.readLine()) != null){
                String regex="\\p{Punct}+";
                String info[]=str.split(regex);
                System.out.print("城市:"+info[22]+info[18]);
                System.out.print('\n'+"时间:"+info[49]+"年"+info[50]+"月"+info[51]+"日"+info[53]);
                System.out.print('\n'+"温度:"+info[47]+"-"+info[45]);
                System.out.print('\n'+"天气:"+info[67]+" "+info[63]+info[65]);
                System.out.print('\n'+info[69]);
            }
            br.close();//网上资源使用结束后，数据流及时关闭
            isReader.close();
        } 
        catch(Exception exp){
            System.out.println(exp);
        }
    }
}